<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增商品轮播图')" />
    <th:block th:include="include :: jasny-bootstrap-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-image-add" th:object="${storeGoods}">
            <div class="form-group" style="display: none;">    
                <label class="col-sm-3 control-label is-required">商品：</label>
                <div class="col-sm-8">
                    <input name="goodsId" id="productId" class="form-control" type="text" th:field="*{goodsId}" required>
                </div>
            </div>
          <div class="form-group">
                <label class="col-sm-2 control-label">主图: </label>
                <div class="col-sm-10">
                    <input name="image" id="image" class="form-control" type="hidden">
                    <input id="fileinput-demo-1" name="file" type="file" multiple>
                </div>
            </div>
        </form>
    </div>
   <th:block th:include="include :: footer" />
    <th:block th:include="include :: jasny-bootstrap-js"/>
    <th:block th:include="include :: bootstrap-fileinput-css" />
    <th:block th:include="include :: bootstrap-fileinput-js" />
    <script type="text/javascript">
    var prefix = ctx + "shop/image"
    
    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/add", $('#form-image-add').serialize());
        }
    }
    $("#fileinput-demo-1").fileinput({
        'theme': 'explorer-fas',
        'uploadUrl': '/common/upload',
        overwriteInitial: false,
        initialPreviewAsData: true,
        initialPreview: [
        ]
    });

    $("#fileinput-demo-1").on("fileuploaded", function (event, data, previewId, index) {
        console.log(data.response);
        if(data.response.code == 0){
            $('#image').val(data.response.url);
        }
    });

    </script>
</body>
</html>